package com.bzsg.simpleMediaPlayer

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.bzsg.simpleMediaPlayer.ui.pager.video.VideoPlayerScreen
import com.bzsg.simpleMediaPlayer.viewModel.VideoStateViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import kotlin.getValue

// 目标 Activity 中接收参数
@AndroidEntryPoint
class PlayerActivity : ComponentActivity() {
    private val viewModel: VideoStateViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        lifecycleScope.launch {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                viewModel.orientationEvent.collect { orientation ->
                    requestedOrientation = orientation
                }
            }
        }
        enableEdgeToEdge()
        setContent {
            VideoPlayerScreen()
        }
    }
}
